package edu.kaifadui.lmbase.controller;


import edu.kaifadui.lmbase.pojo.Major;
import edu.kaifadui.lmbase.service.MajorService;
import edu.kaifadui.lmbase.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 陈世杰
 * @since 2022-02-24
 */
@RestController
public class MajorController {
    @Autowired
    private MajorService majorService;

    @PostMapping("/major")
    public Result addMajor(@RequestBody Major major){
        if (majorService.save(major)){
            return new Result(200,major,"专业添加成功");
        }
        return new Result(0,major,"专业添加失败");
    }

    @DeleteMapping("/major")
    public Result deleteMajor(@RequestBody Major major){
        Map<String, Object> map = new HashMap<>(1);
        map.put("major_id",major.getMajorId());
        if (majorService.removeByMap(map)){
            return new Result(200,major,"专业删除成功");
        }
        return new Result(0,major,"专业删除失败");
    }
}

